package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysRetail;
import com.ruoyi.system.service.ISysRetailService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 散户信息管理Controller
 *
 * @author ruoyi
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/system/retail")
public class SysRetailController extends BaseController
{
    @Autowired
    private ISysRetailService sysRetailService;

    /**
     * 查询散户信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:retail:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRetail sysRetail)
    {
        startPage();
        List<SysRetail> list = sysRetailService.selectSysRetailList(sysRetail);
        return getDataTable(list);
    }

    /**
     * 导出散户信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:retail:export')")
    @Log(title = "散户信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRetail sysRetail)
    {
        List<SysRetail> list = sysRetailService.selectSysRetailList(sysRetail);
        ExcelUtil<SysRetail> util = new ExcelUtil<SysRetail>(SysRetail.class);
        util.exportExcel(response, list, "散户信息管理数据");
    }

    /**
     * 获取散户信息管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:retail:query')")
    @GetMapping(value = "/{rId}")
    public AjaxResult getInfo(@PathVariable("rId") Long rId)
    {
        return success(sysRetailService.selectSysRetailByRId(rId));
    }

    /**
     * 新增散户信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:retail:add')")
    @Log(title = "散户信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRetail sysRetail)
    {
        return toAjax(sysRetailService.insertSysRetail(sysRetail));
    }

    /**
     * 修改散户信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:retail:edit')")
    @Log(title = "散户信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRetail sysRetail)
    {
        return toAjax(sysRetailService.updateSysRetail(sysRetail));
    }

    /**
     * 删除散户信息管理
     */
    @PreAuthorize("@ss.hasPermi('system:retail:remove')")
    @Log(title = "散户信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rIds}")
    public AjaxResult remove(@PathVariable Long[] rIds)
    {
        return toAjax(sysRetailService.deleteSysRetailByRIds(rIds));
    }

    /**
     * 修改散户生产状态
     */
    @PreAuthorize("@ss.hasPermi('system:retail:edit')")
    @Log(title = "散户信息管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody SysRetail sysRetail)
    {
        return toAjax(sysRetailService.updateSysRetailStatus(sysRetail));
    }
}
